<?php

function route_class()
{
    return str_replace('.', '-', Route::currentRouteName());
}

function api($data, $msg, $code)
{
    return response()->json([
        "code" => (int)$code,
        "msg" => (string)$msg,
        "data" => $data
    ]);
}

function getStaticUrl($path)
{
    // 如果 image 字段本身就已经是完整的 url 就直接返回
    if (\Illuminate\Support\Str::startsWith($path, ['http://', 'https://'])) {
        return $path;
    }

    return "https://static.nfangxu.com/" . $path . "?imageslim";
}

function token(\App\Models\User $user)
{
    return md5(
        $user->id.time()
    );
}